package mod.luckymod.data;

import mod.luckymod.ModBlocks;
import mod.luckymod.ModItems;
import net.minecraft.advancements.critereon.InventoryChangeTrigger;
import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.recipes.*;
import net.minecraft.world.item.crafting.Ingredient;
import org.jetbrains.annotations.NotNull;

import java.util.function.Consumer;

public class RecipeGenerator extends RecipeProvider {
    public RecipeGenerator(DataGenerator generator) {
        super(generator.getPackOutput());
    }
    @Override
    protected void buildRecipes(@NotNull Consumer<FinishedRecipe> consumer) {

        SimpleCookingRecipeBuilder.smelting(
                        Ingredient.of(ModItems.RAW_SODIUM),
                        RecipeCategory.MISC,
                        ModItems.SODIUM_INGOT.get(),
                        1.0f, // 原版经验设为0
                        200   // 需要3个燃料（600/200=3）
                ).unlockedBy("has_RawSodium", has(ModItems.RAW_SODIUM))
                .save(consumer);
        ShapelessRecipeBuilder.shapeless(RecipeCategory.BUILDING_BLOCKS, ModBlocks.SODIUM_BLOCK.asItem(), 1)// 魔法在这里
                .requires(ModBlocks.SMALL_SODIUM.asItem(), 4)
                .unlockedBy("has_item", has(ModBlocks.SMALL_SODIUM.asItem()))
                .save(consumer);
        ShapedRecipeBuilder.shaped(RecipeCategory.COMBAT, ModItems.SODIUM_HELMET.get())
                .pattern("DDD")
                .pattern("D D")
                .pattern("   ")
                .define('D', ModItems.SODIUM_INGOT.get())
                .unlockedBy("has_sodium", has(ModItems.SODIUM_INGOT))
                .save(consumer);
        ShapedRecipeBuilder.shaped(RecipeCategory.COMBAT, ModItems.SODIUM_BOOTS.get())
                .pattern("   ")
                .pattern("D D")
                .pattern("D D")
                .define('D', ModItems.SODIUM_INGOT.get())
                .unlockedBy("has_sodium", has(ModItems.SODIUM_INGOT))
                .save(consumer);
        ShapedRecipeBuilder.shaped(RecipeCategory.COMBAT, ModItems.SODIUM_CHESTPLATE.get())
                .pattern("D D")
                .pattern("DDD")
                .pattern("DDD")
                .define('D', ModItems.SODIUM_INGOT.get())
                .unlockedBy("has_sodium", has(ModItems.SODIUM_INGOT))
                .save(consumer);
        ShapedRecipeBuilder.shaped(RecipeCategory.COMBAT, ModItems.SODIUM_LEGGING.get())
                .pattern("DDD")
                .pattern("D D")
                .pattern("D D")
                .define('D', ModItems.SODIUM_INGOT.get())
                .unlockedBy("has_sodium", has(ModItems.SODIUM_INGOT))
                .save(consumer);
    }
    private static InventoryChangeTrigger.TriggerInstance has(net.minecraft.world.item.Item item) {
        return InventoryChangeTrigger.TriggerInstance.hasItems(
                ItemPredicate.Builder.item().of(item).build()
        );
    }
}
